package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.admin.api.dto.*;
import com.lyf.scm.admin.domain.remote.allocationservice.SalePlanDirectlyDifferinRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 直营预测计划_目标与销售计划差异
 *
 * @author wangchlei
 * @date 2020/08/05
 */
@Service
@Slf4j
public class SalePlanDirectlyDifferinFacade {
    @Resource
    private SalePlanDirectlyDifferinRemote salePlanDirectlyDifferinRemote;


    /**
     * 按条件查询直营预测计划_目标与销售计划差异(周)
     *
     * @param salePlanDirectlyDifferinDTO
     * @return
     */
    public PageInfoExpandDTO<SalePlanDirectlyDifferinInfoDTO> listWeekBySelective(SalePlanDirectlyDifferinDTO salePlanDirectlyDifferinDTO) {
        log.info("按条件查询直营预测计划_目标与销售计划差异(周)入参:SalePlanDirectlyDifferinDTO:{}", JSON.toJSONString(salePlanDirectlyDifferinDTO));
        Response<PageInfoExpandDTO<SalePlanDirectlyDifferinInfoDTO>> response = salePlanDirectlyDifferinRemote.listWeekBySelective(salePlanDirectlyDifferinDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 图表数据接口
     *
     * @param salePlanDirectlyDifferinDTO
     * @return {@link EChartsDTO}
     **/
    public EChartsExpandDTO listAllByCycles(SalePlanDirectlyDifferinDTO salePlanDirectlyDifferinDTO) {
        log.info("图表数据接口入参:SalePlanDirectlyDifferinDTO:{}", JSON.toJSONString(salePlanDirectlyDifferinDTO));
        Response<EChartsExpandDTO> response = salePlanDirectlyDifferinRemote.listAllByCycles(salePlanDirectlyDifferinDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public feign.Response export(SalePlanDirectlyDifferinDTO salePlanDirectlyDifferinDTO,Integer type) {
        log.info("直营预测计划_目标与销售计划导出入参:SalePlanDirectlyDifferinDTO:{}", JSON.toJSONString(salePlanDirectlyDifferinDTO));
        return salePlanDirectlyDifferinRemote.export(salePlanDirectlyDifferinDTO,type);
    }

    public void delete(String opSign) {
        log.info("删除直营预测计划_目标与销售计划:{}", JSON.toJSONString(opSign));
        salePlanDirectlyDifferinRemote.delete(opSign);
    }
}
